//
//  YZAuthenticationAuditVC.m
//  VET
//
//  Created by 刘文靖 on 2018/6/29.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZAuthenticationAuditVC.h"
#import "YZMainTabBarController.h"
#import "YZUser.h"
#import "YZStatementHeader.h"
@interface YZAuthenticationAuditVC ()
@property (weak, nonatomic) IBOutlet UILabel *countLabel;
@property (weak, nonatomic) IBOutlet UIImageView *authImageView;
@property (weak, nonatomic) IBOutlet UILabel *authStatusLabel;
@property (weak, nonatomic) IBOutlet UILabel *authDscLabel;
@property (nonatomic, weak) NSTimer *countdownTimer;
@property (nonatomic, assign) NSTimeInterval countdownInterval;
@end
#define kCountTime 8
@implementation YZAuthenticationAuditVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"专业认证";
    if ([YZUser sharedInstance].authStatus) {//1：认证中
        [self.authImageView setImage:[UIImage imageNamed:@""]];
    }else{//2：认证成功
        [self.authImageView setImage:[UIImage imageNamed:@""]];
        self.authStatusLabel.text = @"认证成功";
        self.authDscLabel.text = @"您的资质审核已认证成功!";
    }
    /**=======后来又说不要自动倒计时跳转了=======
    self.countdownInterval = kCountTime;
    self.countLabel.attributedText =  [self attributedString];

    [self setupCountdownTimer];*/
}

- (NSMutableAttributedString *)attributedString{
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%.0f秒自动跳转回工作台",self.countdownInterval]];
    [attStr addAttribute:NSForegroundColorAttributeName value:yzColorGE range:(NSMakeRange(0, 1))];
    return attStr;
}

- (void)setupCountdownTimer {
    [self releaseCountdownTimer];
    self.countdownTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateCountdown) userInfo:nil repeats:YES];
    [[NSRunLoop mainRunLoop] addTimer:self.countdownTimer forMode:NSRunLoopCommonModes];
}

- (void)releaseCountdownTimer {
    [self.countdownTimer invalidate];
}

- (void)updateCountdown{
    --self.countdownInterval;
    if (self.countdownInterval) {
        self.countLabel.attributedText =  [self attributedString];
    }else{
        [self releaseCountdownTimer];
        YZMainTabBarController *tabBarController = (YZMainTabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
        tabBarController.selectedIndex = 0;
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}

//- (void)dealloc{
//    [self releaseCountdownTimer];
//}
@end
